/**
 * 
 */
package br.srv.full.geoProcessing.entities.localidades;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.OrderBy;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.FetchType;
import javax.persistence.Basic;

/**
 * @author Carlos Delfino
 * 
 */
@Entity
@Table(name="LocaleType")
public class LocaleType {

	@Id
	@Column(length=3)
	private String acronym;
	
	@Basic
	@Column(length=40)
	private String name;
	
	@OneToMany(fetch=FetchType.EAGER)
	@JoinTable(name="LocaleTypeCanUseWith", joinColumns = @JoinColumn(name = "canUseType", referencedColumnName = "acronym") )
	private List<LocaleType> canUseWith;

	public LocaleType() {

	}

	public LocaleType(String p_type, String p_name) {
		acronym = p_type;
		name = p_name;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param p_name
	 *            the name to set
	 */
	public void setName(String p_name) {
		name = p_name;
	}

	/**
	 * @return the acronym
	 */
	public String getAcronym() {
		return acronym;
	}

	/**
	 * @param p_acronym
	 *            the acronym to set
	 */
	public void setAcronym(String p_acronym) {
		acronym = p_acronym;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return  getName();
	}

	/**
	 * @param p_typeCanUse
	 */
	public void add(LocaleType p_typeCanUse) {
		getCanUseWith().add(p_typeCanUse);
	}

	/**
	 * @return the canUseWith
	 */
	public List<LocaleType> getCanUseWith() {
		if (canUseWith == null) {
			canUseWith = new ArrayList<LocaleType>();
			
		}

		return canUseWith;
	}

	/**
	 * @param p_canUseWith the canUseWith to set
	 */
	public void setCanUseWith(List<LocaleType> p_canUseWith) {
		canUseWith = p_canUseWith;
	}
	
	
}
